package com.hzy.greendao.greendao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.hzy.greendao.ResultBean.TaskConvert;
import com.hzy.greendao.Task;

import com.hzy.greendao.ResultBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "RESULT_BEAN".
*/
public class ResultBeanDao extends AbstractDao<ResultBean, Long> {

    public static final String TABLENAME = "RESULT_BEAN";

    /**
     * Properties of entity ResultBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Datas = new Property(1, String.class, "datas", false, "DATAS");
    }

    private final TaskConvert datasConverter = new TaskConvert();

    public ResultBeanDao(DaoConfig config) {
        super(config);
    }
    
    public ResultBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"RESULT_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"DATAS\" TEXT);"); // 1: datas
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"RESULT_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, ResultBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Task datas = entity.getDatas();
        if (datas != null) {
            stmt.bindString(2, datasConverter.convertToDatabaseValue(datas));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ResultBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Task datas = entity.getDatas();
        if (datas != null) {
            stmt.bindString(2, datasConverter.convertToDatabaseValue(datas));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public ResultBean readEntity(Cursor cursor, int offset) {
        ResultBean entity = new ResultBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : datasConverter.convertToEntityProperty(cursor.getString(offset + 1)) // datas
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ResultBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setDatas(cursor.isNull(offset + 1) ? null : datasConverter.convertToEntityProperty(cursor.getString(offset + 1)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(ResultBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(ResultBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(ResultBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
